ARD2  RC2
Airbag Reference Demonstrator using MPC5604P
MPC5604P_HWInit.c
00001 
00002 /*
00003  *
00004  * FILE : MPC5604P_HWInit.c
00005  *
00006  * DESCRIPTION:
00007  *  This file contains all MPC5604P derivative needed initializations, 
00008  *  and all initializations for the MPC5604P boards which are supported.
00009  *  This includes setting up the External Bus Interface to allow access
00010  *  to memory on the external bus, and ensuring there is a valid entry in
00011  *  the MMU for the external memory access.
00012  */
00013 
00014 /*----------------------------------------------------------------------------*/
00015 /* Includes                                                                   */
00016 /*----------------------------------------------------------------------------*/
00017 
00018 #include "MPC5604P.h"        /* MPC55xx platform development header            */
00019 #include "MPC5604P_HWInit.h"
00020 
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024 
00025 /*******************************************************/
00026 /* MPC5604P derivative specific hardware initialization */
00027 /*******************************************************/
00028 
00029 /* Symbol L2SRAM_LOCATION is defined in the application linker command file (.lcf) 
00030    It is defined to the start of the L2SRAM of the MPC5604P. 
00031 */
00032 /*lint -esym(752, L2SRAM_LOCATION) */
00033 extern long L2SRAM_LOCATION;  
00034 
00035 
00036 __asm void INIT_Derivative(void) 
00037 {
00038 nofralloc
00039 
00040     /* MPC5604P SRAM initialization code                                 */
00041     lis r11,L2SRAM_LOCATION@h       /* Base of SRAM, 64-bit word aligned */
00042     ori r11,r11,L2SRAM_LOCATION@l
00043 
00044     li r12,320        /* Loops to cover 40K SRAM; 40k/4 bytes/32 GPRs = 320 */
00045     mtctr r12
00046 
00047     init_l2sram_loop:
00048         stmw r0,0(r11)        /* Write 32 GPRs to SRAM                     */
00049         addi r11,r11,128      /* Inc the ram ptr; 32 GPRs * 4 bytes = 128B */
00050         bdnz init_l2sram_loop /* Loop for 40k of SRAM                      */
00051 
00052         //  *(volatile unsigned int*)0xfff38010 = 0x0000c520; 
00053         e_lis r9,0x0001
00054         e_add16i r9,r9,-15072
00055         e_lis r8,0xfff4
00056         e_stw r9,-32752(r8)
00057         //  *(volatile unsigned int*) 0xfff38010 = 0x0000d928; 
00058         e_lis r9,0x0001
00059         e_add16i r9,r9,-9944
00060         e_lis r8,0xfff4
00061         e_stw r9,-32752(r8)
00062         // *(volatile unsigned int*) 0xfff38000 = 0xff00000A; 
00063         e_lis r3,0xff00
00064         se_addi r3,0x000a
00065         e_lis r8,0xfff4
00066         e_stw r3,-32768(r8)        
00067         
00068     blr
00069 }
00070 
00071 /*******************************************************/
00072 /* MPC5604P boards specific hardware initializations    */
00073 /*******************************************************/
00074 
00076 #define MAKE_HLI_COMPATIBLE(hli_name, c_expr) enum { hli_name=/*lint -e30*/((int)(c_expr)) };
00077 
00078 /*----------------------------------------------------------------------------*/
00079 /* Function declarations                                                      */
00080 /*----------------------------------------------------------------------------*/
00081 
00082 /* Initialize a set of contiguous PCRs */
00083 __asm void InitPCRs(void); 
00084 
00085 /* Initialize the SIU External Bus Interface */
00086 __asm void __initSIUExtBusInterface(void);
00087 
00088 /* Initialize the used EBI Chip Selects */
00089 __asm void __initEBIChipSelects(void);
00090 
00091 /* Write one MMU Table Entry */
00092 __asm void WriteMMUTableEntry( void );
00093 
00094 /* Initialize the needed MMU Table entries */
00095 __asm void __initMMUExternalMemory(void);
00096 
00097 /*----------------------------------------------------------------------------*/
00098 /* Function implementations                                                   */
00099 /*----------------------------------------------------------------------------*/
00100 
00101 __asm void INIT_ExternalBusAndMemory(void) 
00102 {
00103 nofralloc
00104 
00105     mflr     r28
00106     
00107     /* Initialize the SIU External Bus Interface */
00108     bl __initSIUExtBusInterface
00109     /* Initialize the used EBI Chip Selects */
00110     bl __initEBIChipSelects
00111     /* Initialize the needed MMU Table entries */
00112     bl __initMMUExternalMemory
00113     
00114     mtlr     r28
00115     
00116     blr
00117 }
00118 
00119 /*----------------------------------------------------------------------------*/
00120 /* External Memory Locations from lcf file                                    */
00121 /*----------------------------------------------------------------------------*/
00122 
00123 #if INIT_USED_BOARD==MPC5604PDEMO_AXM_0321
00124 /* Symbol AXM_0321_EXTERNAL_RAM is defined in the application linker command file (.lcf) 
00125    It is defined to the start of the external memory on the MPC5604PDEMO_AXM-0321 board 
00126 */
00127 extern unsigned long AXM_0321_EXTERNAL_RAM[]; 
00128 #endif
00129 
00130 /*----------------------------------------------------------------------------*/
00131 /* SIU External Bus Interface                                                 */
00132 /*----------------------------------------------------------------------------*/
00133 
00134 /* Initialize a set of contiguous PCRs:               */
00135 /* r3: the firts PCR to initialize                    */
00136 /* r4: the value to write in the PCRs                 */ 
00137 /* r5: the number of PCRs to initialize               */
00138 __asm void InitPCRs(void) 
00139 {
00140 nofralloc
00141 
00142     mtctr r5                   /* intialize ctr with the number of PCRs to initialize */
00143     pcr_init_loop:
00144         sth r4,0(r3)           /* Write r4 to current PCR address */
00145         addi r3,r3, 2          /* Inc the memory ptr by 2 to point to the next PCR */
00146         bdnz pcr_init_loop     /* Loop for ctr PCRs */
00147 
00148     blr
00149 }
00150 
00151 /* Initialize the SIU External Bus Interface */
00152 __asm void __initSIUExtBusInterface(void)
00153 { 
00154 MAKE_HLI_COMPATIBLE(SIU_PCR0,&SIU.PCR[0].R)
00155 MAKE_HLI_COMPATIBLE(SIU_PCR4,&SIU.PCR[4].R)
00156 MAKE_HLI_COMPATIBLE(SIU_PCR28,&SIU.PCR[28].R)
00157 MAKE_HLI_COMPATIBLE(SIU_PCR62,&SIU.PCR[62].R)
00158 MAKE_HLI_COMPATIBLE(SIU_PCR64,&SIU.PCR[64].R)
00159 MAKE_HLI_COMPATIBLE(SIU_PCR68,&SIU.PCR[68].R)
00160 nofralloc
00161 
00162     mflr r27
00163 
00164     /*  This initializes the MPC5604P external bus
00165         Set up the pins
00166         Address bus PCR 4 - 27
00167         Configure address bus pins
00168     */
00169     lis r3,SIU_PCR4@h          /* First PCR Address bus is PCR 4 */
00170     ori r3,r3,SIU_PCR4@l
00171     li r5,24                   /* Loop counter to get all address bus PCR (4 to 27) -> 24 PCRs  */
00172     li r4, 0x0440              /* PCRs initialization value */
00173     bl InitPCRs
00174 
00175     /*  Data bus PCR 28-59
00176         Configure data bus pins
00177     */
00178     lis r3,SIU_PCR28@h         /* First PCR for data bus is PCR 28 */
00179     ori r3,r3,SIU_PCR28@l
00180     li r5,32                   /* Loop counter to get all data bus PCR (28-59) -> 32 PCRs  */
00181     li r4, 0x0440              /* PCRs initialization value */
00182     bl InitPCRs
00183 
00184     /*  Configure minimum bus control pins
00185         RD/WR  & BDIP PCR 62/63
00186     */
00187     lis r3,SIU_PCR62@h         /* First PCR for is PCR 62 */
00188     ori r3,r3,SIU_PCR62@l
00189     li r5,2                    /* Loop counter to get all PCR (62-63) -> 2 PCRs  */
00190     li r4, 0x0440              /* PCRs initialization value */
00191     bl InitPCRs
00192 
00193     /*  WE[0-4] PCR 64-67
00194     */
00195     lis r3,SIU_PCR64@h         /* First PCR for is PCR 64 */
00196     ori r3,r3,SIU_PCR64@l
00197     li r5,4                    /* Loop counter to get all PCR (64-67) -> 4 PCRs  */
00198     li r4, 0x0443              /* PCRs initialization value */
00199     bl InitPCRs
00200 
00201     /*  OE & TS
00202     */
00203     lis r3,SIU_PCR68@h         /* First PCR for is PCR 68 */
00204     ori r3,r3,SIU_PCR68@l
00205     li r5,2                    /* Loop counter to get all PCR (68-69) -> 2 PCRs  */
00206     li r4, 0x0443              /* PCRs initialization value */
00207     bl InitPCRs
00208     
00209     /*  Configure the chip selects
00210         CS[0-3]
00211     */
00212     lis r3,SIU_PCR0@h          /* First PCR for is PCR 0 */
00213     ori r3,r3,SIU_PCR0@l
00214     li r5,4                    /* Loop counter to get all PCR (0-3) -> 4 PCRs  */
00215     li r4, 0x0443              /* PCRs initialization value */
00216     bl InitPCRs
00217     
00218     mtlr r27
00219     
00220     blr
00221 }
00222 
00223 /*----------------------------------------------------------------------------*/
00224 /* EBI Chip Selects                                                           */
00225 /*----------------------------------------------------------------------------*/
00226 
00227 /* Initialize the used EBI Chip Selects */
00228 __asm void __initEBIChipSelects(void)
00229 {
00230 #if INIT_USED_BOARD==MPC5604PDEMO_AXM_0321
00231 MAKE_HLI_COMPATIBLE(EBBI_CS0_BR,&EBI.CS[0].BR.R)
00232 MAKE_HLI_COMPATIBLE(EBBI_CS0_OR,&EBI.CS[0].OR.R)
00233 #endif
00234 nofralloc
00235 
00236 #if INIT_USED_BOARD==MPC5604PDEMO_AXM_0321
00237     /*  CY7C1338 512K External SRAM - 4 beat burst, 0 wait
00238         Set up Memory Controller CS0 @ AXM_0321_EXTERNAL_RAM
00239     */
00240     /*  EBI.CS[0].BR.R = (unsigned long)AXM_0321_EXTERNAL_RAM | 0x41UL;
00241     */
00242     lis      r3,AXM_0321_EXTERNAL_RAM@h
00243     addi     r0,r3,AXM_0321_EXTERNAL_RAM@l
00244     ori      r0,r0,0x0041    
00245     lis      r3,EBBI_CS0_BR@ha
00246     ori      r3,r3,EBBI_CS0_BR@l
00247     stw      r0,0(r3)
00248     /*  EBI.CS[0].OR.R = 0xfff80000;
00249     */
00250     lis      r0,0xfff8
00251     lis      r3,EBBI_CS0_OR@h
00252     ori      r3,r3,EBBI_CS0_OR@l
00253     stw      r0,0(r3)    
00254 #endif
00255 
00256     blr
00257 }
00258 
00259 /*----------------------------------------------------------------------------*/
00260 /* Writing to MMU Table Entries                                               */
00261 /*----------------------------------------------------------------------------*/
00262 
00263 /* Write one MMU Table Entry:               */
00264 /* r3, r4, r5 and r6 must hold              */
00265 /* the values of MAS0, MAS1, MAS2 and MAS3  */
00266 __asm void WriteMMUTableEntry( void )
00267 { 
00268 nofralloc
00269 
00270     /* Write MMU Assist Register 0 (MAS0); SPR 624 */
00271     mtspr   624, r3
00272     /* Write MMU Assist Register 1 (MAS1); SPR 625 */
00273     mtspr   625, r4
00274     /* Write MMU Assist Register 2 (MAS2); SPR 626 */
00275     mtspr   626, r5
00276     /* Write MMU Assist Register 3 (MAS3); SPR 627 */
00277     mtspr   627, r6
00278     /* Write the table entry */
00279     tlbwe
00280 
00281     blr
00282 }
00283 
00284 /* Initialize the needed MMU Table entries */
00285 __asm void __initMMUExternalMemory(void)
00286 {
00287 #if INIT_USED_BOARD==MPC5604PDEMO_AXM_0321
00288 /* Set up MMU for External Memory
00289    Base address = 0x2000_0000
00290    16 MByte Memory Space, Not Guarded, Cachable, All Access
00291 */
00292 MAKE_HLI_COMPATIBLE(AXM_0321_EXT_RAM_MAS0_VALUE,MAS0_VALUE(2))
00293 /* 16 MB memory space, valid, protected, global which matches with all process IDs */
00294 MAKE_HLI_COMPATIBLE(AXM_0321_EXT_RAM_MAS1_VALUE,MAS1_VALUE(V_VALID, IPROT_PROTECTED, TID_GLOBAL, 0, TSIZE_16MB)) 
00295 MAKE_HLI_COMPATIBLE(AXM_0321_EXT_RAM_MAS2_FLAGS,MAS2_FLAGS(SHARED_CACHE_STATE_NOT_USED, WRITE_BACK, CACHEABLE, MEM_COHERENCE_NREQ, NOT_GUARDED, BIG_ENDIAN ))
00296 MAKE_HLI_COMPATIBLE(AXM_0321_EXT_RAM_MAS3_FLAGS,MAS3_FLAGS(READ_WRITE_EXECUTE))
00297 #endif
00298 nofralloc
00299 
00300      mflr     r27
00301 
00302 #if INIT_USED_BOARD==MPC5604PDEMO_AXM_0321
00303      /* load r3 with MAS0 value */
00304      lis r3,AXM_0321_EXT_RAM_MAS0_VALUE@h
00305      ori r3,r3,AXM_0321_EXT_RAM_MAS0_VALUE@l
00306      
00307      /* load r4 with MAS1 value */
00308      lis r4,AXM_0321_EXT_RAM_MAS1_VALUE@h
00309      ori r4,r4,AXM_0321_EXT_RAM_MAS1_VALUE@l
00310      
00311      /* load r5 with the external RAM address from the lcf file */       
00312      lis r5,AXM_0321_EXTERNAL_RAM@h
00313      ori r5,r5,AXM_0321_EXTERNAL_RAM@l
00314      
00315      /* mask with 0xfffff000 */
00316      clrrwi   r5,r5,12
00317      
00318      /* copy the masked external ram address to r6 also */
00319      mr r6,r5
00320      
00321      /* end MAS2 setup in r3 */
00322      ori r5,r5,AXM_0321_EXT_RAM_MAS2_FLAGS@l
00323      
00324      /* end MAS3 setup in r4 */
00325      ori r6,r6,AXM_0321_EXT_RAM_MAS3_FLAGS@l
00326      
00327      /* write the MMU entry defined through r3, r4, r5 and r6 */ 
00328      bl WriteMMUTableEntry 
00329 #endif
00330 
00331      mtlr r27
00332 
00333      blr
00334 }
00335 
00336 #ifdef __cplusplus
00337 }
00338 #endif